<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<u-form-item prop="name" label="姓名" label-width="auto">
					<u-input v-model="formData.name" placeholder="请输入姓名" />
				</u-form-item>
				<u-form-item prop="birthDate" label="出生日期" label-width="auto">
					<dateTime v-model="formData.birthDate" :showLabel="false" :showArrow="false" :required="false"
						:disabled="true" className="new-date-picker" placeholder="请选择出生日期" jnpfKey="date"></dateTime>
				</u-form-item>
				<u-form-item prop="education" label="学历" label-width="auto">
					<u-input v-model="formData.education" name="education" placeholder="请输入学历"
						@click="handleEducation" />
				</u-form-item>
				<u-form-item prop="origin" label="籍贯" label-width="auto">
					<u-input v-model="formData.origin" placeholder="请输入籍贯" />
				</u-form-item>
				<u-form-item prop="yearsOfResidence" label="定居年数" label-width="auto">
					<u-input v-model="formData.yearsOfResidence" placeholder="请输入定居年数" type="number" />
					<view slot="right">年</view>
				</u-form-item>
				<u-form-item prop="relationshipBetweenActualControllerAndLegalRepresentative" label="实际控制人与法定代表人关系说明"
					label-width="auto">
					<u-input v-model="formData.relationshipBetweenActualControllerAndLegalRepresentative"
						placeholder="请输入实际控制人与法定代表人关系说明" />
				</u-form-item>
				<u-form-item prop="isMortgaged" label="实际控制人两年内是否发生过变更" label-width="auto" label-position="left">
					<view slot="right">
						<u-switch v-model="isMortgaged" @change="change"></u-switch>
					</view>
				</u-form-item>
				<u-form-item prop="professionalSkillsOrHonors" label="附件信息" label-width="auto">
					<JNPFUpload v-model="attendanceFileList" :fileSize='2' :limit='10' :showLabel="false"
						@uploading="uploading">
					</JNPFUpload>
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" shape="circle" @click="onSubmit">确定</u-button>
			</view>
		</view>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
	</view>
</template>

<script>
	import dateTime from '@/components/dateTime/dateTime.vue'
	import wPicker from '@/components/w-picker/w-picker.vue'
	const apiUrl = "/api/Jiushi/Customeractualcontroller";
	export default {
		components: {
			dateTime,
			wPicker
		},
		name: 'Customeractualcontroller',
		data() {
			return {
				formData: {
					id: undefined,
					customerId: undefined,
					businessId: this.$helper.getUuid(),
					name: undefined,
					birthDate: undefined,
					education: undefined,
					origin: undefined,
					marriageStatus: undefined,
					spouseSituation: undefined,
					yearsOfResidence: undefined,
					childrenSituation: undefined,
					familyLocalResidenceStatus: undefined,
					familyPropertyInformation: undefined,
					professionalSkillsOrHonors: undefined,
					relationshipBetweenActualControllerAndLegalRepresentative: undefined,
					hasActualControllerChangedInTwoYears: undefined,
				},
				educationData: this.$jnpf.dictionaryData('Education'),
				pickerList: [],
				isSearchShow: false,
				mode: '', //底部弹窗分类
				isMortgaged: false,
				attendanceFileList: [],
				btnDisabled: false
			}
		},
		onLoad(options) {
			if (options.cid) {
				this.formData.customerId = options.cid
			}
			if (options.id) {
				this.formData.id = options.id
				this.init()
			}
		},
		methods: {
			uploading(flag) {
				this.btnDisabled = flag
			},
			input(list) {
				this.btnDisabled = true
				if (list.length > 0) {
					let count = list.filter(item => item.progress == 100)
					if (count = list.length) {
						this.btnDisabled = false
					}
				}
			},
			handleEducation() {
				this.pickerList = this.educationData;
				this.mode = "selector";
				this.$refs.picker.show();
				this.$eventHub.$off('popupmodality');
				this.$eventHub.$on('popupmodality', (data) => {
					this.formData.education = data.result;
					this.$eventHub.$off('popupmodality');
				});
			},
			change(e) {
				console.log('change', e);
				this.formData.isMortgaged = e ? 1 : 0
			},
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: apiUrl + "/" + this.formData.id,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.formData = res.data.data
						if (this.formData.professionalSkillsOrHonors) {
							this.attendanceFileList = res.data.data.professionalSkillsOrHonors.split(',').map(
								item => {
									let tempItem = {
										url: item
									}
									return tempItem
								})
						}
					}
				});
			},

			/* 表单提交 */
			onSubmit() {
				this.formData.professionalSkillsOrHonors = this.attendanceFileList.map(item => {
					return item.url
				}).join(',')
				let url = apiUrl;
				let method = "POST";
				if (this.formData.id) {
					url = url + "/" + this.formData.id;
					method = "PUT";
				}
				this.formData.hasActualControllerChangedInTwoYears = this.formData.isMortgaged
				this.$helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg('保存成功', 'success');
						uni.setStorage({
							key: "refreshPage",
							data: true
						})
						uni.navigateBack();
					}
				});
			},
		}
	}
</script>

<style>

</style>